package com.superman.supermarket.client.composite.preorder.addr;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.utils.ActivityJumpUrl;

/**
 * 确认订单地址模块
 * 
 * @author superman
 * @version 2018年8月12日下午9:47:43
 */
public class PreorderAddrModule extends Composite implements IUIModule {

	interface PreorderAddrModuleUiBinder extends UiBinder<Widget, PreorderAddrModule> {
	}

	private static PreorderAddrModuleUiBinder uiBinder = GWT.create(PreorderAddrModuleUiBinder.class);

	@UiField
	protected FlowPanel addrpanel;
	@UiField
	protected HTML receiverinfohtml, addresshtml, arrow;

	private Map<String, Object> map;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月12日 下午9:47:40
	 */
	public PreorderAddrModule() {
		initWidget(uiBinder.createAndBindUi(this));
		addDomHandler();
	}

	protected void addDomHandler() {
		addrpanel.addDomHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				// 跳转到选择地址的页面
				String addrId = String.valueOf(map.get("ADDR_ID"));
				ActivityJumpUrl.pushToAddressChoosePage(addrId);
			}
		}, ClickEvent.getType());
	}

	@Override
	public Map<String, Object> getData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setData(Map<String, Object> map) {
		this.map = map;
		boolean isDefault = Double.parseDouble(String.valueOf(map.get("IS_DEFAULT"))) == 1;
		receiverinfohtml.setHTML(String.valueOf(map.get("RECEIVER")) + "&nbsp;&nbsp;&nbsp;&nbsp;" + String.valueOf(map.get("RECEIVE_TEL"))
				+ (isDefault ? "&nbsp;&nbsp;<span style='color:#fff;font-size:13px'>[默认]</span>" : ""));
		addresshtml.setText(String.valueOf(map.get("AREA")) + String.valueOf(map.get("RECEIVE_ADDR")));
	}

}
